/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package base.node;

import base.message.Data;
import base.message.Message;
import base.node.Node;
import java.util.Date;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import routing.RouteNodeAbstraction;
import routing.RouteNodeList;
import base.node.NodeInfo;
import base.node.NodeUtils;
import base.node.PowerPolicy;
import java.io.Serializable;

/**
 * Wireless Sensor Node
 * @author artem, Arvanitis Ioannis
 */
public class WSNode extends Node implements NodeUtils, Serializable {

	public WSNode(NodeInfo nodeInfo, PowerPolicy pp, int portOffset) {
		super(portOffset, nodeInfo, pp);
	}

	public void move() {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public void setUpPowerPolicy() {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public boolean processMessage() {
		throw new UnsupportedOperationException("Not supported yet.");
	}

//	@Override
//	protected void intercept(Message message) {
//		if (message.getMessageType() == Message.msgTypes.REQUEST_FOR_NODE_NEIGHBOUR) {
//			print("Received " + message.getMessageType().toString() + " message from node " + message.getData().getNodeInfo().getId());
//			updateNeighboursArrayList(message);
//			waitMsecs(1000);
//			replyToNeighbourRequest(message);
//		}
//
//		if (message.getMessageType() == Message.msgTypes.ANSWER_TO_NODE_NEIGHBOUR_REQUEST) {
//			print("Received " + message.getMessageType().toString() + " message from node " + message.getData().getNodeInfo().getId());
//			updateNeighboursArrayList(message);
//		}
//		checkForNeighbours();
//        print(message.getMessageId());
//	}

//	@Override
//	protected void manipulateReceivedMessage(Message message) {
//		throw new UnsupportedOperationException("Not supported yet.");
//	}

//	private void replyToNeighbourRequest(Message orig_msg) {
//		Message tmp = new Message();
//		tmp.setData(new Data(0, 0, nodeInfo));
//		RouteNodeList rnl = new RouteNodeList(1);
//		rnl.add(new RouteNodeAbstraction(orig_msg.getData().getNodeInfo().getId(), true, null));
//		tmp.setTargetNodes(rnl);
//		tmp.setMessageType(Message.msgTypes.ANSWER_TO_NODE_NEIGHBOUR_REQUEST);
//		tmp.setSendTime(new Date().getTime());
//		tmp.setHopCount(0);
//		tmp.setMessageSize(1024);
//		tmp.setMessageId(generateMessageId());
//		print("Replying to node " + orig_msg.getData().getNodeInfo().getId() + " sending an ANSWER_TO_NEIGHBOUR_REQUEST message");
//		send(tmp);
//	}

	/**
	 * A simple function that waits
	 * @param maxWaitTime The upper bound of waiting, in msecs
	 */
//	private void waitMsecs(int maxWaitTime) {
//		int time;
//		synchronized (this) {
//			try {
//				time = new Random().nextInt(maxWaitTime);
//				print("Waiting " + String.valueOf(time) + "msecs");
//				wait(time);
//			} catch (InterruptedException ex) {
//				Logger.getLogger(WSNode.class.getName()).log(Level.SEVERE, null, ex);
//			}
//		}
//	}
}
